package
{
	import com.youease.chris.ActionQueue;
	import com.youease.chris.action.AnimateAction;
	import com.youease.chris.action.GroupAction;
	import com.youease.chris.action.TweenAction;
	import com.youease.chris.animate.Animation;
	import com.youease.chris.util.AnimationFactory;
	import com.youease.chris.util.Tween;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	
	public class AnimationQueue extends Sprite
	{
		[Embed(source="gen.png")]
		private var gen:Class;
		[Embed(source="player.png")]
		private var player:Class;
		
		private var bmd:Bitmap = new gen() as Bitmap;
		private var bmd2:Bitmap = new gen() as Bitmap;
		
		public function AnimationQueue()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
//			init();
//			testDelay();
			testAnimate();
		}
		
		private function testAnimate():void {
			var arr:Array = AnimationFactory.instance.cutBitmapDataSingleArray((new player() as Bitmap).bitmapData,1,9,60,108);
			var animate:Animation = new Animation(arr,8);
			this.addChild(animate);
			var animateAction:AnimateAction = new AnimateAction(animate);
			
			var delayQueue:ActionQueue = new ActionQueue([new TweenAction(animate,2,{x:400,y:400})]);
			
			var queue:ActionQueue = new ActionQueue([delayQueue,animateAction],1);
			
			var addAnimate:AnimateAction = new AnimateAction(animate);
			var groupAction:GroupAction = new GroupAction([queue,addAnimate]);
			groupAction.execute();
		}
		
		private function testDelay():void {
			this.addChild(bmd);
			this.addChild(bmd2);
			bmd.x = 0,bmd.y = 0;
			bmd2.x = 0,bmd2.y = 400;
			var actions:Array = [];
			actions.push(new TweenAction(this.bmd,3,{x:500,y:500}));
			var delayQueue:ActionQueue = new ActionQueue(actions,1);
			
			new ActionQueue([delayQueue,new TweenAction(this.bmd2,3,{x:500,y:0})]).execute();
		}
		
		private function init():void {
			this.addChild(bmd);
			this.addChild(bmd2);
			bmd.x = 0,bmd.y = 0;
			bmd2.x = 0,bmd2.y = 400;
			
			var actions:Array = [];
//			var tweenAction:TweenAction = new TweenAction(this.bmd,0.1,{x:500,y:500});
//			actions.push(tweenAction);
//			actions.push( new TweenAction(this.bmd,0.8,{x:500,y:0}) );
			var list:Array = [];
			var tweenAction1:TweenAction = new TweenAction(this.bmd,0.5,{x:500,y:0});
			var tweenAction2:TweenAction = new TweenAction(this.bmd2,0.5,{x:500,y:400});
			list.push(tweenAction1,tweenAction2);
			var group:GroupAction = new GroupAction(list);
			actions.push(group);
			
			actions.push(new TweenAction(this.bmd,0.5,{x:500,y:500}));
			
			var queue:ActionQueue = new ActionQueue(actions);
			queue.execute();
		}
		
	}
}